package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.ShoppingCart;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 购物车
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 根据菜品id查询菜品内容
     * @param dishId
     * @return
     */
    ShoppingCart getByDishId(Long dishId);
    /**
     * 根据套餐id查询菜品内容
     * @param setmealId
     * @return
     */
    ShoppingCart getBySetmealId(Long setmealId);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount,number, create_time) VALUES " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount}, #{number}, #{createTime})")
    @AutoFill(OperationType.INSERT)
    void save(ShoppingCart shoppingCart);

    /**
     * 根据id查看购物车
     * @param userId
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> getByUserId(Long userId);

    /**
     * 查看购物车是否已经添加该菜品
     * @param shoppingCart
     */
    ShoppingCart getShoppingCart(ShoppingCart shoppingCart);

    /**
     * 购物车+1
     * @param shoppingCart
     */
    void addShoppingCart(ShoppingCart shoppingCart);

    /**
     * 购物车-1
     * @param shoppingCart
     */
    void subShoppingCart(ShoppingCart shoppingCart);

    /**
     * 删除购物车
     * @param shoppingCart
     */
    void delShoppingCart(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

}
